import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css'
import VueCookies from 'vue-cookies'
import Cookies from 'js-cookie'
import moment from 'moment'
import vshare from 'vshare'

Vue.use(vshare)
 
Vue.prototype.$moment = moment

Vue.prototype.$store = store
Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.use(VueCookies)


router.beforeEach((to, from,next) => {
  //to： 即将要进入的目标路由
  //from：当前导航正要离开的路由
  // next()：进行下一个路由
  const token = Cookies.get('token')
  if (!token && to.name !== 'login') {
	  next({name: 'login'})
  } else if (token && to.name === 'login') {
	  next({name: 'home'})
  } else {
	  next()
  }
  
})

// router.prefix("/api")

new Vue({
  router,
  store,
  moment,
  render: h => h(App)
}).$mount('#app')
